#pragma once
#include "DXAMLCommon.h"
#include "CPanel.h"
#include "CPopup.h"



class CPopupRoot :
	public CPanel
{
private: 
	CPopupRoot(CCoreServices * pCore);
protected: 
	virtual HRESULT MeasureOverride(struct XSIZEF availableSize, struct XSIZEF & desiredSize);
	virtual HRESULT ArrangeOverride(struct XSIZEF finalSize, struct XSIZEF & newFinalSize);
	virtual HRESULT NWRenderChildren(const struct SharedRenderParams & sharedRP, const struct NWRenderParams & nwRP);
	virtual ~CPopupRoot();
	virtual CTransitionCollection * GetTransitionsForChildElementNoAddRef(CUIElement * pChild);
	virtual HRESULT PrintChildren(const struct SharedRenderParams & sharedPrintParams, const struct D2DPrecomputeParams & cp, const struct D2DRenderParams & printParams);
public: 
	virtual XUINT32 GetTypeIndex() const;
	static HRESULT Create(CDependencyObject * * ppObject, CREATEPARAMETERS * pCreate);
	virtual XBOOL GetIsLayoutElement();
	virtual XBOOL SkipNameRegistrationForChildren();
	HRESULT AddToOpenPopupList(CPopup * pPopup);
	HRESULT RemoveFromOpenPopupList(CPopup * pPopup, XBOOL bAsyncRelease);
	HRESULT AddToDeferredOpenPopupList(CPopup * pPopup);
	HRESULT ClearPopups();
	HRESULT OnPublicRootChanged();
	XBOOL HasOpenPopups();
	HRESULT GetOpenPopups(XINT32 * pnCount, CPopup * * * pppPopups);
	HRESULT NWPreRenderChildren();
	HRESULT ClearPrintDirtyFlagOnOpenPopups();
	CPopup * GetTopmostLightDismissPopup();
	HRESULT HitTestPopups(const HitTestPolygon & target, CHitTestResults * pHitElements, XBOOL fHitMultiple, CUIElement * pSubTreeRoot);
	HRESULT HitTestPopups(const struct XPOINTF & target, CHitTestResults * pHitElements, XBOOL fHitMultiple, CUIElement * pSubTreeRoot);
protected: 
	virtual HRESULT BoundsTestChildren(const HitTestPolygon & target, struct IBoundsTestCallback * pCallback, enum BoundsWalkHitResult::Value * pResult);
	virtual HRESULT BoundsTestChildren(const struct XPOINTF & target, struct IBoundsTestCallback * pCallback, enum BoundsWalkHitResult::Value * pResult);
	virtual HRESULT GenerateChildOuterBounds(struct XRECTF_RB * pBounds);
	virtual HRESULT HitTestLocalInternal(const HitTestPolygon & target, XBOOL * pHit);
	virtual HRESULT HitTestLocalInternal(const struct XPOINTF & target, XBOOL * pHit);
	virtual HRESULT OnPointerPressed(struct Xcp_IDependencyObject * pEventArgs);
	virtual HRESULT OnKeyUp(struct Xcp_IDependencyObject * pEventArgs);
	virtual HRESULT OnKeyDown(struct Xcp_IDependencyObject * pEventArgs);
private: 
	virtual HRESULT LeavePCSceneSubgraph();
	CXcpList<CPopup> * m_pOpenPopups;
	xvector<CPopup *> * m_pDeferredPopups;
	struct XSIZEF m_availableSizeAtLastMeasure;
};


